<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
  <link rel="stylesheet" type="text/css" href="/themes/default/easyui.css">
  <link rel="stylesheet" type="text/css" href="/themes/icon.css">
  <script type="text/javascript" src="/jquery.min.js"></script>
  <script type="text/javascript" src="/jquery.easyui.min.js"></script>
  <script type="text/javascript" src="/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
    <h1>欢迎进入注册页面</h1>
    <form>
        <label for="username">申请账号:</label>
        <input type="text" id="username" name="username" placeholder="请输入登录账号"><br><br>
        <label for="password">填写密码:</label>
        <input type="password" id="password" name="password" placeholder="请输入登录密码"><br><br>
        <label for="phone">您的手机号:</label>
        <input type="text" id="phone" name="phone" placeholder="请输入手机号"><br><br>
        <label for="code">验证码:</label>
        <input type="text" id="code" name="code" placeholder="请输入验证码"><br><br>
        <input type="button" value="获取验证码" onclick="getCode()" id="aaa">
    </form>
    <br><br>
    <input type="button" value="申请注册" onclick="insertUser()">
</body>
<script type="text/javascript">
    function insertUser(){
        let username = $("#username").val();
        let password = $("#password").val();
        let phone = $("#phone").val();
        let code = $("#code").val();

        let user = {
            username: username,
            password : password,
            phone : phone,
            code : code
        };
        let newUser = JSON.stringify(user);

        $.ajax({
            url: "/login/insertUser",
            type: "post",
            data: newUser,
            dataType: 'json',
            contentType:'application/json;charset=utf-8',
            success: function (data){
                if (data.code === 500) {
                    alert(data.msg);
                    location.reload();
                }else {
                    alert(data.msg);
                    location.href="/login/login.html";
                }
            }
        })
    }

    function getCode(){
        let phone = $("#phone").val();
        let user = {
            phone : phone
        }
        let newUser = JSON.stringify(user);

        $.ajax({
            url: "/login/getCode",
            type: "POST",
            data: newUser,
            dataType: 'json',
            contentType:'application/json;charset=utf-8',
            success:function (data){
                if (data.code === 500) {
                    alert(data.msg);
                    location.reload();
                }else {
                    alert(data.msg);
                    $("#aaa").linkbutton('disable');
                }
            }
        })
    }
</script>
</html>
